const path = require('path');
const webpack = require('webpack');
const glob = require('glob-all');
const PurifyCSSPlugin = require('purifycss-webpack');
const ExtractTextWebpackPlugin = require('extract-text-webpack-plugin');
const webpackConfig = {
    entry: {
        app: './src/app.js'
    },
    output: {
        path: path.resolve(__dirname, './dist'),
        filename: '[name].bundle.js',
        publicPath: ''
    },
    module: {
        rules: [{
            test: /\.css/,
            loader: ExtractTextWebpackPlugin.extract({
                fallback: {
                    loader: 'style-loader',
                    options: {
                        singleton: true
                    }
                },
                use: [{
                    loader: 'css-loader',
                    options: {
                        minimize: true
                    }
                }]
            })
        }]
    },
    plugins: [
        new ExtractTextWebpackPlugin({
            filename: '[name].min.css',
            allChunks: false
        }),
        new PurifyCSSPlugin({
            paths: glob.sync([
                path.join(__dirname, './*.html'),
                path.join(__dirname, './src/*.js')
            ])
        }),
        new webpack.optimize.UglifyJsPlugin()
    ]
};
module.exports = webpackConfig;